<template>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="编辑模板字段" :append-to-body="true" :visible="modalEdit" @close="modalEdit=false" @opened="opened" @closed="closed">
        <el-transfer :props="props" v-model="smallFields" :data="smallData"></el-transfer>
        <el-transfer :props="props" v-model="bigFields" :data="bigData"></el-transfer>
        <el-transfer :props="props" v-model="outFields" :data="outData"></el-transfer>
        <div slot="footer">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" :loading="modalLoading" @click="ok">确定</el-button>
        </div>
    </el-dialog>
    </div>
</template>
<script>
import Constants from '@/utils/constants'
export default {
    name: 'Customer',
    data() {
        return {
            props: {
                key: 'value',
                label: 'label'
            },
            smallData: [],
            bigData: [],
            outData: [],
            outFields: [],
            bigFields: [],
            smallFields: [],
            modalEdit: false,
            modalLoading: false,
            customerId: "",

        };
    },
    mounted: function() {

        this.init();
    },
    methods: {
        init() {
            for (var ky in Constants.printFields) {
                this.smallData.push({
                    label: Constants.printFields[ky],
                    value: ky
                });
                this.bigData.push({
                    label: Constants.printFields[ky],
                    value: ky
                });
                this.outData.push({
                    label: Constants.printFields[ky],
                    value: ky
                });
            }
          

        },

        opened() {



        },
        closed: function() {

            this.searchLoading = false;
            this.smallFields=[];
            this.bigFields=[];
            this.outFields=[];
        },
        showDialog(id,sfs,bfs,ofs) {
            this.customerId = id;
            this.modalEdit = true;
            if(sfs){
                this.smallFields=sfs.split(",");
            }
            if(bfs){
                this.bigFields=bfs.split(",");
            }
            if(ofs){
                this.outFields=ofs.split(",");
            }
        },

        ok: function() {
            
            // if (this.smallFields.length <= 0) {
            //     this.errorMessage("请选好小箱子字段！")
            //     return;
            // }
            // debugger;
            // if (this.bigFields.length <= 0) {
            //     this.errorMessage("请选好大箱子字段！")
            //     return;
            // }
            // if (this.outFields.length <= 0) {
            //     this.errorMessage("请选好外箱子字段！")
            //     return;
            // }
            
            var me = this;
            me.modalLoading = true;
            var params={
                smallFields:this.smallFields.join(","),
                bigFields:this.bigFields.join(","),
                outFields:this.outFields.join(","),
                id:this.customerId
            };
            me.$http.post("/sys/customer/doSaveFields.action", params).then(response => {
                var body = response;
                if (body.status == 0) {
                    me.successMessage("保存成功！");
                    me.modalEdit = false;
                    me.$emit("ok");

                } else {
                    me.errorMessage(body.info);
                }
                me.modalLoading = false;
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.customer = {};
            this.modalEdit = false;
            this.$emit("cancel");
        }
    }
}
</script>
<style scoped>
</style>